#include <iostream>
#include <vector>
#include <string>
using std::cout;
using std::endl;
using std::string;
using std::vector;

// 单个位图
template <size_t N>
class bitset
{
public:
    bitset()
    {
        _bs.reserve(N / 8 + 1);
    }
    void set(size_t x)
    {
        size_t i = x / 8;
        size_t j = x % 8;
        _bs[i] |= (1 << j);
    }
    void reset(size_t x)
    {
        size_t i = x / 8;
        size_t j = x % 8;
        _bs[i] &= (~(1 << j));
    }
    bool Is_num(size_t x)
    {
        size_t i = x / 8;
        size_t j = x % 8;
        return _bs[i] & (1 << j);
    }

private:
    vector<char> _bs;
    // vector<int> _bs;
};

template <size_t N>
class two_bit
{
public:
    void set(size_t x)
    {
        if (!_b1.Is_num(x) && !_b2.Is_num(x))
        {
            _b2.set(x);
        }
        else if (!_b1.Is_num(x) && _b2.Is_num(x))
        {
            _b1.set(x);
            _b2.reset(x);
        }
        else if (_b1.Is_num(x) && !_b2.Is_num(x))
        {
            _b2.set(x);
        }
        else
        {
        }
    }
    void reset(size_t x)
    {
        if (_b1.Is_num(x) && _b2.Is_num(x))
        {
            _b2.reset(x);
        }
        else if (_b1.Is_num(x) && !_b2.Is_num(x))
        {
            _b1.reset(x);
            _b2.set(x);
        }
        else if (!_b1.Is_num(x) && _b2.Is_num(x))
        {
            _b2.reset(x);
        }
        else
        {
        }
    }
    void Print(size_t x)
    {
        if (!_b1.Is_num(x) && _b2.Is_num(x))
        {
            cout << "该数据" << x << "存在" << endl;
        }

        // if (!_b1.Is_num(x) && !_b2.Is_num(x))
        // {
        //     cout << "该数据" << x << "不存在" << endl;
        // }
        // else if (!_b1.Is_num(x) && _b2.Is_num(x))
        // {
        //     cout << "该数据" << x << "存在1次" << endl;
        // }
        // else if (_b1.Is_num(x) && !_b2.Is_num(x))
        // {
        //     cout << "该数据" << x << "存在2次" << endl;
        // }
        // else
        // {
        //     cout << "该数据" << x << "存在3次及以上" << endl;
        // }
    }

private:
    bitset<N> _b1;
    bitset<N> _b2;
};

int main()
{
    // bitset<0xffffffff> b1;
    // b1.set(1000);
    // cout << b1.Is_num(1000) << endl;
    two_bit<0xffffffff> b;
    // vector<int> v(10);
    vector<int> v;
    v.push_back(0);
    v.push_back(0);
    v.push_back(0);
    v.push_back(0);
    v.push_back(1);
    v.push_back(1);
    v.push_back(1);
    v.push_back(2);
    v.push_back(2);
    v.push_back(3);
    for (auto e : v)
    {
        cout << e << " ";
    }
    cout << endl;

    for (auto e : v)
    {
        b.set(e);
    }
    for (auto e : v)
    {
        b.Print(e);
    }
    // for (auto e : v)
    // {
    //     b.set(e);
    //     b.Print(e);
    // }
    return 0;
}